package com.jz.algorithm.Tree;

import java.util.ArrayList;
import java.util.List;

/**
 * @Classname TraversalNode
 * @Description 遍历节点
 * @Date 2021-12-20 15:47
 * @Author Jz
 * @Version
 */
public class TraversalNode {


    public static List preTraversalNode(TreeNode root){


        ArrayList<Object> objects = new ArrayList<>();
        List list = preOrder(root, objects);
        return  list;


    }

    private static List preOrder(TreeNode root, ArrayList<Object> objects) {
        if (root==null){
            return objects;
        }
        objects.add(root.value);
        preOrder(root.leftNode,objects);
        preOrder(root.leftNode,objects);
        return objects;
    }
    private static List leftOrder(TreeNode root, ArrayList<Object> objects) {
        if (root==null){
            return objects;
        }
        preOrder(root.leftNode,objects);
        objects.add(root.value);
        preOrder(root.leftNode,objects);
        return objects;
    }
    private static List rightOrder(TreeNode root, ArrayList<Object> objects) {
        if (root==null){
            return objects;
        }
        preOrder(root.leftNode,objects);
        preOrder(root.leftNode,objects);
        objects.add(root.value);
        return objects;
    }
}
